﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_SPINSPEED(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_SPINSPEED(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_SPINSPEED(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_SPINSPEED(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] = GetSeq();
                InsertICC_SPINSPEED(dwLocal, ITXDBVERSION);
            }
            UpdateICC_SPINSPEED(dwLocal);
        }
        public void InsertICC_SPINSPEED(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            string table = "VVPACK";  //VVPMANDANT	VVPLIEFSCH	VVPPACKNR
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_SPINSPEED(ROWNID, MTYPE,YNDES, YN, MDAILY,MSPIND,CCOLOR,UMIN,EFF, TPM, GKM,RTIME,RSPEED,REMARK)"
                                + " VALUES (:ROWNID, :MTYPE,:YNDES, :YN, :MDAILY,:MSPIND,:CCOLOR,:UMIN,:EFF, :TPM, :GKM,:RTIME,:RSPEED,:REMARK)";
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("MTYPE", OracleType.NVarChar).Value = dwData["MTYPE"].ToString();
                    or1.Parameters.Add("YNDES", OracleType.NVarChar).Value = dwData["YNDES"].ToString();
                    or1.Parameters.Add("YN", OracleType.NVarChar).Value = dwData["YN"].ToString();
                    or1.Parameters.Add("MDAILY", OracleType.NVarChar).Value = dwData["MDAILY"].ToString();
                    or1.Parameters.Add("MSPIND", OracleType.NVarChar).Value = dwData["MSPIND"].ToString();
                    or1.Parameters.Add("CCOLOR", OracleType.NVarChar).Value = dwData["CCOLOR"].ToString();
                    or1.Parameters.Add("UMIN", OracleType.NVarChar).Value = dwData["UMIN"].ToString();
                    or1.Parameters.Add("EFF", OracleType.NVarChar).Value = dwData["EFF"].ToString();
                    or1.Parameters.Add("TPM", OracleType.NVarChar).Value = dwData["TPM"].ToString();
                    or1.Parameters.Add("GKM", OracleType.NVarChar).Value = dwData["GKM"].ToString();
                    or1.Parameters.Add("RTIME", OracleType.NVarChar).Value = dwData["RTIME"].ToString();
                    or1.Parameters.Add("RSPEED", OracleType.NVarChar).Value = dwData["RSPEED"].ToString();
                    or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_SPINSPEED(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_SPINSPEED WHERE   ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM ICC_SPINSPEED";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_SPINSPEED";
            Return = Result;
            return Return;
        }
        public void UpdateICC_SPINSPEED(DataRow dwData, int options = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (options)
            {
                case 1:
                    #region====Command====
                    or1.CommandText = "UPDATE ICC_SPINSPEED SET "
                        + "MTYPE=:MTYPE,"
                        + "YNDES=:YNDES,"
                        + "YN=:YN,"
                        + "MDAILY=:MDAILY, "
                        + "MSPIND=:MSPIND,"
                        + "CCOLOR=:CCOLOR,"
                        + "UMIN=:UMIN, "
                        + "EFF=:EFF,"
                        + "TPM=:TPM,"
                        + "GKM=:GKM, "
                        + "RTIME=:RTIME,"
                        + "RSPEED=:RSPEED,"
                        + "REMARK=:REMARK  "
                        + " WHERE  "
                        + "   ROWNID=:ROWNID ";
                    #endregion
                    #region====Parameters====
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("MTYPE", OracleType.NVarChar).Value = dwData["MTYPE"].ToString();
                    or1.Parameters.Add("YNDES", OracleType.NVarChar).Value = dwData["YNDES"].ToString();
                    or1.Parameters.Add("YN", OracleType.NVarChar).Value = dwData["YN"].ToString();
                    or1.Parameters.Add("MDAILY", OracleType.NVarChar).Value = dwData["MDAILY"].ToString();
                    or1.Parameters.Add("MSPIND", OracleType.NVarChar).Value = dwData["MSPIND"].ToString();
                    or1.Parameters.Add("CCOLOR", OracleType.NVarChar).Value = dwData["CCOLOR"].ToString();
                    or1.Parameters.Add("UMIN", OracleType.NVarChar).Value = dwData["UMIN"].ToString();
                    or1.Parameters.Add("EFF", OracleType.NVarChar).Value = dwData["EFF"].ToString();
                    or1.Parameters.Add("TPM", OracleType.NVarChar).Value = dwData["TPM"].ToString();
                    or1.Parameters.Add("GKM", OracleType.NVarChar).Value = dwData["GKM"].ToString();
                    or1.Parameters.Add("RTIME", OracleType.NVarChar).Value = dwData["RTIME"].ToString();
                    or1.Parameters.Add("RSPEED", OracleType.NVarChar).Value = dwData["RSPEED"].ToString();
                    or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    #endregion
                    break;
            }

            Connect2Proxy(or1);
        }
    }
}
